<template>
  <div>
    <div class="title">
      <i class="el-icon-discount">美奥口腔用户重置密码</i>
    </div>
    <video
        style="position: absolute; z-index: -1; width: 1900px"
        class="mp41"
        src="../assets/img/111.png"
        autoplay="autoplay"
        loop="loop"
        muted="muted"
    ></video>
    <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
        style="
        color: #FFF;
        position: absolute;
        z-index: 1;
        width: 500px;
        margin-left: 650px;
        margin-top: 200px;
      "
    >
      <i class="tips">请认真输入您新密码</i>
      <el-form-item label="新密码" prop="password">
        <el-input v-model="ruleForm.password" type="password"></el-input>
      </el-form-item>
      <el-form-item label="再次确认密码" prop="confirm_pwd">
        <el-input v-model="ruleForm.confirm_pwd" type="password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')"
        >提交
        </el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script scoped>
import Reset_Password from "./Reset_Password";

export default {
  components: {Reset_Password},
  data() {
    var checkAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("密码不能为空"));
      }
    };
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.ruleForm.password) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        confirm_pwd: "",
        password: "",
      },
      rules: {
        pass: [{validator: validatePass, trigger: "blur"}],
        checkPass: [{validator: validatePass2, trigger: "blur"}],
        password: [{validator: checkAge, trigger: "blur"}],
      },
    };
  },
  methods: {
    submitForm() {
      let user = this.$getSessionStorage('user')
      this.$axios.post(this.$settings.BASE_URL + 'user/password/check_pwd/', {
        user: user,
        confirm_pwd: this.ruleForm.confirm_pwd,
        password: this.ruleForm.password
      }).then(response => {
        if (response.data.code === 100) {
          this.$message({
            message: response.data.msg,
            type: 'success',
            duration: 1000
          })
          this.$router.push({
            path: '/login'
          })
        } else {
          this.$message({
            message: response.data.msg,
            type: 'warning',
            duration: 1000
          })
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
.title {
  position: absolute;
  z-index: 0;
  margin-left: 580px;
  margin-top: 50px;
  color: #e56363;
  font-size: 50px;
}

.tips {
  position: absolute;
  z-index: 1;
  width: 500px;
  margin-left: 270px;
  margin-top: 140px;
   color: #e56363;
}

.sms {
  color: orange;
  cursor: pointer;
  display: inline-block;
  width: 70px;
  text-align: center;
  user-select: none;
}
</style>